<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line("quickPrintReceipt");?></h3>
<p class="required">Ghi chú : * Thông tin bắt buộc</p>
<style>
    .fone_num_cls{
        width:13% !important;
    }
    .btn-success,.btn-danger,.btn-primary.delete{
        vertical-align: top;
    }
    .required{color:red;}
</style>

<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" customerAssess-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open('',array('id'=>'ajaxform'));?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                //thong tin dat cho
                echo form_label($this->lang->line('booking_place_code').' <span class="required">*</span>', 'booking_place_code');
                echo form_input(array('name' => 'booking_place_code', 'id' => 'booking_place_code', 'value' => '','required'=>'required'));
                echo form_error('booking_place_code');
                
                //ho ten
                echo form_label($this->lang->line('customersName'), 'customersName');
                echo form_input(array('name' => 'customersName', 'id' => 'customersName', 'value' => '','readonly' => 'true'));
                echo form_error('customersName');
                
                //dia chi
                echo form_label($this->lang->line('address'), 'address');
                echo form_input(array('name' => 'address', 'id' => 'address', 'value' => '','readonly' => 'true'));
                echo form_error('address');
                
                //gia bán
                echo form_label($this->lang->line('sale_fare'), 'sale_fare');
                echo form_input(array('name' => 'sale_fare', 'id' => 'sale_fare', 'value' => '','readonly' => 'true'));
                echo form_input(array('type'=>'hidden','name' => 'sale_fare_fake', 'id' => 'sale_fare_fake', 'value' => ''));
                echo form_error('sale_fare');
                
                //hidden
                echo form_input(array('type'=>'hidden','name' => 'booker', 'id' => 'booker', 'value' => ''));
                ?>
            </div>
        </div>
        <div class="top-button">
                <a class="fancy-sl">
                    <img style="cursor: pointer;" alt="In phiếu thu" title="In phiếu thu" src="<?php echo STATIC_URL;?>/backend/images/icon/phieuthu_nhanh.png">
                </a>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>
<?php $this->load->view('templates/backend/lib'); ?>

<script src="<?php echo base_url().'static/templates/backend/js/jquery.maskedinput.js';?>"></script>
<script src="<?php echo base_url().'static/templates/backend/js/autoNumeric.js';?>"></script>
<link rel="stylesheet" href="<?php echo STATIC_URL;?>/backend/css/jquery.fancybox.css">
<script type="text/javascript" src="<?php echo STATIC_URL;?>/backend/js/jquery.fancybox.js"></script>


<script>
$(document).ready(function() {        
        $('#net_fare').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
        
        $("#booking_place_code").blur(function() {
                    var booking_place_code       = $("#booking_place_code").val().toUpperCase();

                    if(/\s+/.test(booking_place_code) || booking_place_code==""){
                        alert("Mã đặt chỗ chứa khoảng trống! Vui lòng xem lại");return false;
                    }
                    
                    $("#loading-image").show();
                    setTimeout(function () {
                    $.ajax(
                    {
                            type:'POST',
                            url : '/auth/others/checkPnr',
                            data : { booking_place_code: booking_place_code},
                            success: function(responseData) {
                                $("#loading-image").hide();
                                if(responseData){
                                    var data                = JSON.parse(responseData);
                                    
                                    document.getElementById("customersName").value             = data[0]['name'];
                                    document.getElementById("address").value                   = data[0]['address'];
                                    document.getElementById("sale_fare").value                 = FormatNumber(data[0]['sale_fare']);
                                    document.getElementById("sale_fare_fake").value            = UnFormatNumber(data[0]['sale_fare']);
                                    document.getElementById("booker").value                    = data[0]['firstname'];
                                } else {
                                    alert("Mã đặt chỗ không tồn tại!");return false;
                                }
                                
                            },
                            error: function (responseData) {
                                alert('POST failed.');
                            }
                    });

                },2000);
                    
                    
        });


        $(".fancy-sl").on('click',function(e){
                if($("#booking_place_code").val()==""){
                    alert("Vui lòng nhập mã đặt chỗ!");$("#booking_place_code").focus();return false;
                }
            
                $.ajax({
                    type        : "POST",
                    cache       : false,
                    url         : "/auth/others/quickPrintReceiptTemplate",
                    data        : $("#ajaxform").serializeArray(),
                    success: function(data) {
                            $.fancybox(data, {
                                    margin		: 0,
                                    padding		: 0,
                                    maxWidth	: '480px',
                                    maxHeight	: '400px',
                                    fitToView	: false,
                                    width		: '100%',
                                    height		: '100%',
                                    autoSize	: false,
                                    closeClick	: false,
                                    openEffect	: 'none',
                                    closeEffect	: 'none',
                                    titleShow	: true,
                                    closeBtn	: false,
                            }); // fancybox
                    }
                });
                e.preventDefault();	//STOP default action
        });
});
    
function FormatNumber(x) {
    if (typeof x === "undefined") {
        return '';
    } else {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' VNĐ';
    }
};
///,|VNĐ|\s/g
function UnFormatNumber(x) {
    if (typeof x === "undefined") {
        return '';
    } else {
    return x.toString().replace(/,|VNĐ|\s/g, "");
    }
};
    
    
</script>